package com.qianji.controller;

import com.qianji.pojo.ActiveResultDto;
import com.qianji.pojo.ThirdPartyDto;
import com.qianji.service.ActiveResultService;
import com.qianji.service.ThirdPartyService;
import com.qianji.utils.Result;
import com.qianji.vo.Introduction;
import com.qianji.vo.ParameterVO;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author 钟丽诗
 * @Date 2021.4.15
 * 活动结果（活动奖品）
 */
@Slf4j
@RestController
@RequestMapping("/activeResult/")
public class ActiveResultController {

    @Autowired
    private ActiveResultService activeResultService;

    @Autowired
    private ThirdPartyService thirdPartyService;

    /**
     * 新增活动结果
     * @param activeResultDto
     * @return
     */
    @ApiOperation("新增活动结果")
    @RequestMapping(value = "add",method = RequestMethod.POST)
    Result add(@RequestBody ActiveResultDto activeResultDto){
        Integer status =  activeResultService.add(activeResultDto);
        if(status != 1){
            return new Result(500,"增加失败");
        }
        return new Result(200,"增加成功");
    }

    /**
     * 修改活动结果
     * @param activeResultDto
     * @return
     */
    @ApiOperation("修改活动结果")
    @RequestMapping(value = "update",method = RequestMethod.POST)
    Result update(@RequestBody ActiveResultDto activeResultDto){
        Integer status =  activeResultService.update(activeResultDto);
        if(status != 1){
            return new Result(500,"修改失败");
        }
        return new Result(200,"修改成功");
    }

    /**
     * 根据活动id查询活动结果
     * @param introduction
     * @return
     */
    @ApiOperation("根据活动id查询活动结果")
    @RequestMapping(value = "findByActiveId",method = RequestMethod.POST)
    Result findByActiveId(@RequestBody Introduction introduction){
        ActiveResultDto activeResultDto = new ActiveResultDto();
        activeResultDto.setActiveId(introduction.getData().getId());
        return new Result(activeResultService.findActiveResult(activeResultDto));
    }

    /**
     * 查询所有活动结果
     * @return
     */
    @ApiOperation("查询所有活动结果")
    @RequestMapping(value = "findByAll",method = RequestMethod.POST)
    Result findByAll(){
        return new Result(activeResultService.findActiveResult(new ActiveResultDto()));
    }

    /**
     * 根据活动结果id查询活动结果
     * @param introduction
     * @return
     */
    @ApiOperation("根据活动结果id查询活动结果")
    @RequestMapping(value = "findById",method = RequestMethod.POST)
    Result findById(@RequestBody Introduction introduction){
        ActiveResultDto activeResultDto = new ActiveResultDto();
        activeResultDto.setId(introduction.getData().getId());
        return new Result(activeResultService.findActiveResult(activeResultDto));
    }

    /**
     * 返回活动奖品结果
     * @param parameterVO 传入参数
     * @return 返回数据
     */
    @ApiOperation("返回活动奖品结果")
    @RequestMapping(value = "findActivePrize",method = RequestMethod.POST)
    Result findActivePrize(@RequestBody ParameterVO parameterVO){


        log.info("-------------------------获取奖品入参-----------------------{}",parameterVO);

        List<ThirdPartyDto> list = thirdPartyService.findThirdParty(parameterVO.getData().getPanId(), parameterVO.getData().getNumber());

        return new Result(list);
    }

}
